import router from '@/router'
import { useUserStore } from '@/stores/modules/user'
import { usePermissionStore } from '@/stores/modules/permission'
// 白名单
const whiteList = ['/login']

router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  if (userStore.token) {
    // const permissionStore = usePermissionStore()
    // if (!permissionStore.hasRoute) {
    //   const menus = [
    //     'roleList',
    //     'userManage',
    //     'permissionList',
    //     'articleRanking',
    //     'articleCreate',
    //     'dataDashBoard',
    //     'config',
    //   ]
    //   permissionStore.setRoutes(menus)
    //   next(to)
    // }
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) > -1) {
      next()
    } else {
      next('/login')
    }
  }
})
